package com.flower.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flower.annotation.Log;
import com.flower.domain.dto.buyer.order.OrderQueryDto;
import com.flower.domain.vo.buyer.OrderDetailVO;
import com.flower.domain.vo.buyer.OrderVO;
import com.flower.service.OrderService;
import com.flower.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理端店铺订单
 */
@Slf4j
@RestController
@RequestMapping("/admin/shop/order")
public class ShopOrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 获取店铺订单列表
     * 管理员查看订单不需要buyerId限制，直接传null
     */
    @GetMapping("/list")
    public AjaxResult getShopOrderList(OrderQueryDto orderQueryDto) {
        if (orderQueryDto.getShopId() == null) {
            return AjaxResult.error("店铺ID不能为空");
        }
        
        // 管理员查看店铺订单时，不需要buyerId限制，传null
        Page<OrderVO> page = orderService.getOrderList(null, orderQueryDto);
        return AjaxResult.success(page);
    }

    /**
     * 获取订单详情
     * 管理员查看订单详情不需要buyerId限制，直接传null
     */
    @GetMapping("/{orderId}")
    public AjaxResult getOrderDetail(@PathVariable Integer orderId) {
        OrderDetailVO orderDetail = orderService.getOrderDetail(orderId, null);
        return AjaxResult.success(orderDetail);
    }

    /**
     * 更新订单状态
     */
    @Log(name = "更新订单状态")
    @PutMapping("/status")
    public AjaxResult updateOrderStatus(
            @RequestParam Integer orderId,
            @RequestParam Integer status) {
        
        if (orderId == null) {
            return AjaxResult.error("订单ID不能为空");
        }
        if (status == null) {
            return AjaxResult.error("订单状态不能为空");
        }
        
        orderService.updateOrderStatus(orderId, status);
        return AjaxResult.success();
    }
} 